import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { dataBody } from 'src/utils/dataType';
import { SessionService } from './session.service';
@Injectable({
    providedIn: 'root'
})

export class MateDataService {

    constructor(
        private http: HttpClient,
        private sessionSvc: SessionService
    ) { }

    baseUrl = 'http://localhost:8088/acts/excel-project/';
    // baseUrl = 'http://192.168.180.107:8088/acts/excel-project/';
    // baseUrl = 'http://localhost:8088/acts/excel-project/file-operation/create-file';

    public loginVerification(userInfo: any) {
        // let user = this.sessionSvc.getSessionValue('user')
        return this.http.get(
            this.baseUrl + 'user-operation/login',
            {
                params: {
                    userAcc: userInfo.userAcc,
                    userPwd: userInfo.password
                }
            }

        );
    }

    public postExcelAllData(data: any) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'file-operation/create-file',
            data,
            {
                headers: { 'token': token }
            }
        );
    }

    public getSheetData(objId) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.get(
            this.baseUrl + 'file-operation/query',
            {
                headers: { 'token': token },
                params: {
                    objId: objId,
                }
            }
        );
    }

    public getFileData(orgId) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.get(
            this.baseUrl + 'file-obj/retrieve-by-params',
            {
                headers: { 'token': token },
                params: {
                    orgId: orgId,
                }
            }
        );
    }

    public deleteFile(objId, modifiedBy) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'file-operation/delete-file',
            {
                objId: objId,
                lastModifiedBy: modifiedBy
            },
            {
                headers: { 'token': token }
            }
        )
    }

    public modifyFileName(params) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'file-operation/modify-file-name',
            params,
            {
                headers: { 'token': token }
            }
        )
    }

    public updateSheetData(updateData) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'data-operation/batch-update',
            updateData,
            {
                headers: { 'token': token }
            }
        )
    }

    public deleteSheetRows(deleteRows) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'data-operation/batch-delete',
            deleteRows,
            {
                headers: { 'token': token }
            }
        )
    }

    public addNewRow(newRow) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'data-operation/batch-insert',
            newRow,
            {
                headers: { 'token': token }
            }
        )
    }

    public getUserList(params?) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.get(
            this.baseUrl + `user-operation/query-user-list`,
            {
                headers: { 'token': token },
                params
            }
        ).toPromise();
    }

    public getUserInfo(params) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.get(
            this.baseUrl + `user-operation/query-user-info`,
            {
                headers: { 'token': token },
                params: {
                    userId: params.userId
                }
            }
        ).toPromise();
    }

    public updateUserInfo(userInfo) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'user-operation/update-user-info',
            userInfo,
            {
                headers: { 'token': token }
            }
        )
    }

    public addNewUser(newUserinfo) {
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + 'user-operation/insert-user-info',
            newUserinfo,
            {
                headers: { 'token': token }
            }
        )
    }

    public deleteUser(deleteUserInfo){
        const { token } = this.sessionSvc.getSessionValue('user');
        return this.http.post(
            this.baseUrl + '',
            deleteUserInfo,
            {
                headers: { 'token': token }
            }
        )
    }

}